<?php
defined('_JEXEC') or die('Restricted access');

$db =& JFactory::getDBO();
$query = 'SELECT * FROM `#__nspro_newsletter_openings` WHERE `nid` = "' . JRequest::getInt( 'nid' ) . '" AND `email` = "' . mysql_escape_string($_GET["e"]) . '"';
$db->setQuery($query);
$mnsl = $db->loadObject();

if ($mnsl) {
  $nvalue = $mnsl->openings+1;
  $query = 'UPDATE `#__nspro_newsletter_openings` SET `openings` = "' . $nvalue . '" WHERE `nid` = "' . JRequest::getInt( 'nid' ) . '" AND `email` = "' . mysql_escape_string($_GET["e"]) . '"';
  $db->setQuery($query);
  $db->query();
}
else {
  $query = 'INSERT INTO `#__nspro_newsletter_openings` (`nid`, `openings`, `email`) VALUES("' . JRequest::getInt( 'nid' ) . '", 1, "' . mysql_escape_string($_GET["e"]) . '")';
  $db->setQuery($query);
  $db->query();
}

// create image
$image = imageCreate(1, 1);

// allocate all required colors
if ($_GET["clr"] == 'black') {
  $colorBackgr       = imageColorAllocate($image, 0, 0, 0);
}
else if ($_GET["clr"] == 'red') {
  $colorBackgr       = imageColorAllocate($image, 255, 0, 0);
}
else if ($_GET["clr"] == 'green') {
  $colorBackgr       = imageColorAllocate($image, 0, 255, 0);
}
else if ($_GET["clr"] == 'blue') {
  $colorBackgr       = imageColorAllocate($image, 0, 0, 255);
}
else {
  $colorBackgr       = imageColorAllocate($image, 255, 255, 255);
}


// clear the image space with the background color
imageFilledRectangle($image, 0, 0, 1, 1, $colorBackgr);

header("Content-type:  image/png");

imagePNG($image);

// create an interlaced image for better loading in the browser
imageInterlace($image, 1);
// mark background color as being transparent
imageColorTransparent($image, $colorBackgr);

return true;
?>